﻿--[[
    @Brief  WeGame login control
    @Author jameszhai
    @Date   2017-05-16
--]]

--[[
// 重新启动WeGame
SERVICE_BEGIN(Svr_LoginRetry)
SERVICE_END

// 重新登录
SERVICE_BEGIN(Svr_Relogin)
SERVICE_END

// 登录
SERVICE_BEGIN(Svr_WGLogin)
    JSONB(int, type);       // 登录类型
    JSONB(string, uin);     // 帐号
    JSONB(string, pwd);     // 密码
    JSONB(int, opt);        // 选项
SERVICE_END

// 显示广告
SERVICE_BEGIN(Svr_ShowLoginAD)
    JSONB(string, url);     // 广告的地址
SERVICE_END

// 页面回退
SERVICE_BEGIN(Svr_LoginGoBack)
SERVICE_END

// 切换到指定页面
SERVICE_BEGIN(Svr_SwitchLoginPage)
    JSONB(int, nPageIdx);       // 切换到指定登录页面
SERVICE_END

// 删除指定帐号
SERVICE_BEGIN(Svr_DelSaveAcc)
    JSON(string, sUin);         // 删除指定帐号
SERVICE_END

// TAS退出
SERVICE_BEGIN(Svr_OnTASExit)
SERVICE_END

// 退出TGP
SERVICE_BEGIN(Svr_ExitWeGame)
    JSONB(int, report);         // 0 -- 不上报       1 -- 数据上报
SERVICE_END

// 刷新二维码
SERVICE_BEGIN(Svr_RefreshQR)
SERVICE_END

// Stop QR login
SERVICE_BEGIN(Svr_StopQRLogin)
SERVICE_END

// 取消登录
SERVICE_BEGIN(Svr_CancelLogin)
    JSONB(int, service_id);
    JSONB(int64, uin);
SERVICE_END

// 刷新验证码
SERVICE_BEGIN(Svr_RenewLoginPict)
    JSONB(int, service_id);
SERVICE_END

// 验证码输入
SERVICE_BEGIN(Svr_ValidPictCode)
    JSONB(int, service_id);
    JSONB(string, code);
SERVICE_END

// 重启WeGame
SERVICE_BEGIN(Svr_RestartWG)
SERVICE_END

// 是否隐藏登录界面
SERVICE_BEGIN(Svr_IsHideLogin)
    JSONB(int, hide);           // [OUT] 0 -- not hide  1 -- hide
SERVICE_END

// Get login UIN
SERVICE_BEGIN(Svr_GetLoginUin)
    JSONB(int, uin);            // [OUT]
SERVICE_END

// 显示页面
SERVICE_BEGIN(Svr_ShowContent)
    JSONB(int, show);           // [IN ] 是否显示 0 -- 隐藏  1 -- 显示
SERVICE_END

// 是否可以离线登录
SERVICE_BEGIN(Svr_CanOffline)
    JSONB(int, can_offline);    // [OUT] 是否可以离线登录
SERVICE_END

// 显示错误信息
SERVICE_BEGIN(Svr_ShowLoginErr)
    JSONB(string, err_msg);     // 错误信息
    JSONB(int, err_code);       // 错误码
SERVICE_END

SERVICE_BEGIN(Srv_GetWeChatQRCode)  // 获取微信的二维码
    JSONB(int, req_result_code);
SERVICE_END

// 是否是海外版
SERVER_BEGIN(Svr_IsI18NVer)
    JSONB(int, is_overseas_ver);    // [OUT]
SERVER_END

SERVER_BEGIN(Svr_GetCurLanguage)
    JSONB(int, language);   // [OUT]
SERVER_END

SERVER_BEGIN(Svr_SetLanguage)
    JSONB(int, language);   // [IN]
SERVER_END

SERVICE_BEGIN(Svr_WGLoginCheckProtocal)
SERVICE_END

--]]
TQRLoginError = 
{
    QRLOGIN_ERROR_OK = 0;
    QRLOGIN_ERROR_CONFIRM = 1;
    QRLOGIN_ERROR_TIMEOUT = 2;
    QRLOGIN_ERROR_VERIFYING = 3;
    QRLOGIN_ERROR_FETCH_FAILED = 4;
};


TLoginCtrl = 
{
    InitCtrl = function()
        comm_center.reg_service("Svr_WGLogin", "TLoginCtrl.OnSvrWGLogin");
        comm_center.reg_service("Svr_ExitWeGame", "TLoginCtrl.OnSvrExitWG");
        comm_center.reg_service("Svr_RestartWG", "TLoginCtrl.OnSvrRestart");
        comm_center.reg_service("Svr_IsHideLogin", "TLoginCtrl.OnSvrIsHideLogin");
        comm_center.reg_service("Svr_GetLoginUin", "TLoginCtrl.OnSvrGetLoginUin");

        -- 帐号登录相关
        comm_center.reg_service("Svr_DelSaveAcc", "TLoginCtrl.OnSvrDelAcc");
        comm_center.reg_service("Svr_DelMailSaveAcc", "TLoginCtrl.OnSvrDelMailAcc" );
        comm_center.reg_service("Svr_OnTASExit", "TLoginCtrl.OnSvrTASExit");

        comm_center.reg_service("Svr_Relogin", "TLoginCtrl.OnSvrRelogin");
        comm_center.reg_service("Svr_LoginRetry", "TLoginCtrl.OnSvrRetry");
        comm_center.reg_service("Svr_CanOffline", "TLoginCtrl.OnSvrCanOffline");

        comm_center.reg_service("Svr_ShowLoginErr", "TLoginCtrl.OnSvrShowError");

        -- 页面切换相关
        comm_center.reg_service("Svr_LoginGoBack", "TLoginCtrl.OnLoginGoBack");
        comm_center.reg_service("Svr_SwitchLoginPage", "TLoginCtrl.OnSwitchPage");

        -- 验证码相关
        comm_center.reg_service("Svr_CancelLogin", "TLoginCtrl.OnCancelLogin");
        comm_center.reg_service("Svr_RenewLoginPict", "TLoginCtrl.OnRenewPict");
        comm_center.reg_service("Svr_ValidPictCode", "TLoginCtrl.OnValidPict");

        -- 二维码登录
        comm_center.reg_service("Svr_RefreshQR", "TLoginCtrl.OnRenewQR");
        comm_center.reg_service("Svr_StopQRLogin","TLoginCtrl.OnSvrStopQR");
        comm_center.reg_service("Svr_StopWeChatQRLogin", "TLoginCtrl.OnSvrStopWeChatQR");

        comm_center.reg_service("Svr_ShowContent", "TLoginCtrl.OnSvrShowContent");

        -- 注册一个服务
        --comm_center.reg_service("Svr_IsOverseasVer", "TLoginCtrl.OnSvrIsOverseasVer");
        -- 历史上FN已经用了Svr_IsOverseasVer，需要改名字
        comm_center.reg_service("Svr_IsI18NVer", "TLoginCtrl.OnSvrIsI18NVer");

        comm_center.reg_service("Svr_GetCurLanguage", "TLoginCtrl.OnGetCurLanguage");
        comm_center.reg_service("Svr_SetLanguage", "TLoginCtrl.OnSetLanguage");
        comm_center.reg_service("Svr_GetDPIAwareMode", "TLoginCtrl.OnGetDPIAwareMode");
        comm_center.reg_service("Svr_SetDPIAwareMode", "TLoginCtrl.OnSetDPIAwareMode");

        comm_center.reg_service("Svr_LoginFirstProtocal", "TLoginCtrl.OnShowFistProtocalView");
        comm_center.reg_service("Svr_LoginUpdateProtocal", "TLoginCtrl.OnShowUpdateProtocalView");
        comm_center.reg_service("Svr_CloseLoginProtocalView", "TLoginCtrl.OnCloseProtocalView");


        -- 显示服务器异常TIPS
        event_center.add_listener(login_event.LOGIN_EVT_CHECK_SVRTIPS, 
                                  "TLoginCtrl.OnCheckSvrTips");
        event_center.add_listener(mainframe_event.MAIN_WND_RESTORE, "TLoginCtrl.OnMainWndRestore");
        event_center.add_listener(mainframe_event.MAINFRAME_WND_SHOWN, "TLoginCtrl.OnMainWndShow");
        comm_center.reg_service("Svr_LoginMgr_WeGameSDKLogin_Failed",
                                 "TLoginCtrl.OnSvrWeGameSDKLoginFailed");

        -- Load WeGame login modules
        ierd_tgp.tpf_ui.Require("wegame_login\\str_helper.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\module.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\view.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\token_vfy.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\new_pict_check.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\first_protocal_view.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\update_protocal_view.lua");


        TStrHelper.InitHelper();
        TokenVfy.InitCtrl();

        -- 监听C++事件
        TLoginCtrl.ListenAllEvts();

        -- 获取launcher相关信息
        TLoginCtrl.GetLauncherInfo();

        -- 标记首次运行
        TLoginCtrl.bFstShow = true;

        -- 初始化模块
        TLoginModule.InitModule();
        TLoginView.InitView();
        -- TLoginCtrl.QueryIsBlackMachine();  -- 暂时先配置黑机器的功能
    end;

    UnInitCtrl = function()
        TLoginCtrl.UnListenAllEvts();
        TLoginView.UnInitView();
        TLoginModule.UnInitModule();
    end;

    ListenAllEvts = function()
        -- Event center 事件
        event_center.add_listener(login_event.LOGIN_QRCODE_CFG_SWITCH, "TLoginCtrl.OnQRCfgChange");

        -- 消息监听
        comm_center.listen_broadcast("Msg_UpdateCheck", "TLoginCtrl.OnUpdateChk");
        comm_center.listen_broadcast("Msg_OnDoUpdate", "TLoginCtrl.OnMsgUpdate");
        comm_center.listen_broadcast("Msg_OnSecScanEnd", "TLoginCtrl.OnMsgScanEnd");
        comm_center.listen_broadcast("Broadcast_QueryBlackMachineResult", "TLoginCtrl.OnQueryBlackMachineRlt");
        comm_center.listen_broadcast("Brdcst_Before_Run", "TLoginCtrl.OnBeforeMsgLoopRun");
        comm_center.listen_broadcast("Broadcast_WeChatQRCodeRsp", "TLoginCtrl.OnShowWeChatQRLogin");
        comm_center.listen_broadcast("Broadcast_WeChatQRAuthSucc", "TLoginCtrl.OnWeChatQRAuthSucc");
        comm_center.listen_broadcast("Broadcast_MailBeginLogin", "TLoginCtrl.OnMailBeiginLogin");
        comm_center.listen_broadcast("Msg_ShowBlackListUserNotify", "TLoginCtrl.OnShowBlackListUserNotify");
        comm_center.listen_broadcast("Msg_UserKickOffNotify", "TLoginCtrl.OnShowUserKickOffNotify");
        -- 监听事件
        local pTPFUI = base_utility.get_component_adapter("ITpf_ui", "ierd_tgp.tpf_ui.GetTPFUI();");

        -- login_mgr events
        if nil ~= pTPFUI then
            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_BEGIN, "TLoginCtrl.OnLoginBegin");
            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_FAILED, "TLoginCtrl.OnLoginFail");
            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_SUCCESS, "TLoginCtrl.OnLoginSucc");
            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_PIC_CHECK, "TLoginCtrl.OnPictCheck");
            pTPFUI:AddLuaListener(ierd_tgp.social_network.SOCIAL_NETWORK_EVENT_GET_MY_SOCIAL_TEST_INFO, 
                                  "TLoginCtrl.OnGetIMTestInfo");

            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_TAS_SCANDANGERS, "TLoginCtrl.OnTASDanger");
            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_TAS_EXIT, "TLoginCtrl.OnTASExit");

            pTPFUI:AddLuaListener(ierd_tgp.login_mgr.LOGIN_ON_SHOW_LAUNCH_TIPS, 
                                  "TLoginCtrl.OnShowLaunchTips");
            pTPFUI:AddLuaListener(ierd_tgp.game_library.SHOW_MAIN_WND, "TLoginCtrl.OnShowMain");
            pTPFUI:AddLuaListener(ierd_tgp.game_library.CLOSE_LOGIN, "TLoginCtrl.OnShowMain");
        else
            TGPLog.LogE("LoginC", "Get TPFUI component fail.");
        end;
    end;

    UnListenAllEvts = function()
        -- Event center 事件
        event_center.remove_listener(login_event.LOGIN_QRCODE_CFG_SWITCH, "TLoginCtrl.OnQRCfgChange");

        local pTPFUI = base_utility.get_component_adapter("ITpf_ui", "ierd_tgp.tpf_ui.GetTPFUI();");

        -- login_mgr events
        if nil ~= pTPFUI then
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_BEGIN, "TLoginCtrl.OnLoginBegin");
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_FAILED, "TLoginCtrl.OnLoginFail");
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_LOGIN_SUCCESS, "TLoginCtrl.OnLoginSucc");
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_PIC_CHECK, "TLoginCtrl.OnPictCheck");
            --[[
            -- TAS事件
            pTPFUI:RemoveLuaListener(ierd_tgp.social_network.SOCIAL_NETWORK_EVENT_GET_MY_SOCIAL_TEST_INFO, 
                                     "TLoginCtrl.OnGetIMTestInfo");
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_TAS_EXIT, "TLoginCtrl.OnTASExit");
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_TAS_SCANDANGERS, "TLoginCtrl.OnTASDanger");
            ]]
            pTPFUI:RemoveLuaListener(ierd_tgp.login_mgr.LOGIN_ON_SHOW_LAUNCH_TIPS, 
                                     "TLoginCtrl.OnShowLaunchTips");
            pTPFUI:RemoveLuaListener(ierd_tgp.game_library.SHOW_MAIN_WND, "TLoginCtrl.OnShowMain");
            pTPFUI:RemoveLuaListener(ierd_tgp.game_library.CLOSE_LOGIN, "TLoginCtrl.OnShowMain");
        else
            TGPLog.LogE("LoginC", "UnListen all event, Get TPFUI component fail.");
        end;
    end;

    -- 检查是否launcher启动
    GetLauncherInfo = function ()
        local launcher_cfg = comm_center.call_service("Srv_IsLaunchedByGame",{});
        if launcher_cfg ~= nil and launcher_cfg.is_launcher ~= nil then
            if launcher_cfg.is_launcher > 0 then
                TLoginCtrl.bIsLauncher = true;
                local launch_cmd_info = comm_center.call_service("Svr_GetGameInfoFromCmdline",{});
                if launch_cmd_info ~= nil then
                    TLoginCtrl.zLaunchCmdInfo = launch_cmd_info; 
                end; 
            end;
        end;
    end;

    -- 好友相关
    OnGetIMTestInfo = function(nEvtID, sJson)
        local   zParam = base_utility.json_to_table(sJson);

        if nil ~= zParam and 0 == zParam["result"] then
            TLoginModule.SetIMData(zParam["level"], zParam["invite_code_number"]);
        else
            TGPLog.LogE("LoginC", "On social network event, J->T fail.");
        end;
    end;

    -- 切换到指定页面
    OnSwitchPage = function(zParam)
        if nil ~= zParam and nil ~= zParam["nPageIdx"] then
            return TLoginCtrl.SwitchPage(tonumber(zParam["nPageIdx"]));
        else
            TGPLog.LogE("LoginC", "Switch login page service, param error.");
        end;
        return false;
    end;

    -- 切换页面
    SwitchPage = function(nPageIdx)
        if (TLoginModule.IsHideLogin()) then
            TGPLog.LogI("LoginC", "Switch page, hide login.");
            return true;
        end;

        if TLoginView.IsSamePage(nPageIdx) then
            TGPLog.LogI("LoginC", "Trying to switch to same page:" .. tostring(nPageIdx))
            return true;
        end;

        comm_center.call_service("SvrCloseBrowser", {});

        if (TLoginView.SwitchPage(nPageIdx)) then
            if ELoginPage.lpAccLogin == nPageIdx then           -- 帐号密码登录
                TLoginView.SetSavedList(TLoginModule.GetSavedList());
                if base_utility.CLIENT_TYPE.CHINA_VER ==  base_utility.get_client_version_type()  then
                    TLoginView.ShowQRButton(login_qrcode_config.show_qrcode_switch(), 
                            login_qrcode_config.show_qrcode_animation());
                end
            elseif ELoginPage.lpQKLogin == nPageIdx then        -- 快速登录
                TLoginView.SetLoginedList(TLoginModule.GetQuickAccList());
                TLoginView.ShowQRButton(login_qrcode_config.show_qrcode_switch(), 
                                        login_qrcode_config.show_qrcode_animation());
            elseif ELoginPage.lpQRLogin  == nPageIdx then       -- 二维码登录
                TLoginCtrl.OnRenewQR(nil);
            elseif ELoginPage.lpSecCheck == nPageIdx then       -- 安全检测
                local   zStatus = {};
                zStatus["state"] = TStrHelper.GetString(EStrDefine.STR_SEC_CHECK_TIPS);
                TLoginView.SetStatus(zStatus);
            elseif ELoginPage.lpWeChatQRLogin == nPageIdx then  -- 微信扫描登录
                TLoginCtrl.OnGetWeChatQRcode();
            elseif ELoginPage.lpMailAccLogin == nPageIdx then   -- 邮箱登录
                -- 设置历史账号
                TLoginView.SetMailSavedList(TLoginModule.GetMailSavedList());
            end;

            return true;
        else
            TGPLog.LogE("LoginC", "Switch to page fail:"..tostring(nPageIdx));
            return false;
        end;
    end;

    -- 显示登录界面
    OnShowLogin = function(nEvtID, sJson)
        local dpi_tips_info = {common = 1, key = "wegame_login.dpi_tips_info"};
        local dpi_tips_data = comm_center.call_service("Svr_GetConfig", dpi_tips_info);
        if 0 == dpi_tips_data.exits and ui_utility.get_dpi_scale() > 1.0 then
            -- tips
            TLoginView.ShowDPITips();
            return;
        end
        TLoginCtrl.ShowLogin();
    end;

    ShowLogin = function()
        if TLoginModule.IsHideLogin() then
            -- 初始化一下升级界面，监听升级消息
            TLoginView.InitUpdate();

            TGPLog.LogI("LoginC", "Hide login, do not show login view.");
            return;
        end;

        TLoginView.ShowView();

        -- 设置启动完成的标志
        if TLoginModule.CheckLoginMgr() then
            TLoginModule.pLoginMgr:SetStartupEndTime();
        end

        if TLoginCtrl.bFstShow then
            -- 获取QR状态
            TLoginModule.GetQRStatus();
            
            TLoginModule.StartScan();

            -- 安全检测
            TLoginCtrl.SwitchPage(ELoginPage.lpSecCheck);
            TLoginCtrl.bFstShow = false;
        end;
    end;

    OnBeforeMsgLoopRun = function()
        -- 尝试离线登录
        if not TLoginModule.TryToOffLogin() then
            TLoginModule.TryToAutoLogin();      -- 尝试自动登录
            local req_info = {common = 1, key = "Login_mgr.last_succ_login_type"};
            local login_type_data = comm_center.call_service("Svr_GetLastSuccLoginType", req_info);
            if 0 == login_type_data.exits then
                if base_utility.CLIENT_TYPE.OVERSEA_VER ==  
                    base_utility.get_client_version_type() then
                    login_type = TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin;
                end
            else
                login_type = tonumber(login_type_data.value);
                if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type()
                and TLoginModule.LOGIN_ACCOUNT_TYPE.kQQLogin == login_type then
                    login_type = TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin;
                end
            end
            local index = -1;
            if  TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin == login_type then
                index = ELoginPage.lpMailAccLogin;
            elseif  TLoginModule.LOGIN_ACCOUNT_TYPE.KWeChatLogin == login_type then
                index = ELoginPage.lpWeChatQRLogin;
            elseif  TLoginModule.LOGIN_ACCOUNT_TYPE.KFacebookLogin == login_type then
                index = ELoginPage.lpOverseasLogin;
            end
            TLoginView.nLstPage = index;
        end;
    end;

    -- 扫描结束
    OnMsgScanEnd = function(zParam)
        if TLoginView.IsSamePage(ELoginPage.lpSecCheck) then
            if TLoginModule.GetBlackMachineState() then
                TLoginCtrl.SwitchPage(ELoginPage.lpQRLogin);
                TGPLog.LogI("LoginC", "Scan end, is black machien, switch to qrode login.");
                return;
            end
            local login_type = TLoginModule.LOGIN_ACCOUNT_TYPE.kQQLogin;

            local req_info = {common = 1, key = "Login_mgr.last_succ_login_type"};
            local login_type_data = comm_center.call_service("Svr_GetLastSuccLoginType", req_info);
            if 0 == login_type_data.exits then
                if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type() then
                    login_type = TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin;
                end
            else
                login_type = tonumber(login_type_data.value);
                if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type()
                and TLoginModule.LOGIN_ACCOUNT_TYPE.kQQLogin == login_type then
                    login_type = TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin;
                end
            end

            if  TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin == login_type then
                TLoginCtrl.SwitchPage(ELoginPage.lpMailAccLogin);
            elseif  TLoginModule.LOGIN_ACCOUNT_TYPE.KWeChatLogin == login_type then
                TLoginCtrl.SwitchPage(ELoginPage.lpWeChatQRLogin);
            elseif  TLoginModule.LOGIN_ACCOUNT_TYPE.KFacebookLogin == login_type then
                TLoginCtrl.SwitchPage(ELoginPage.lpOverseasLogin);
            else
               if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type() then
                   TLoginCtrl.SwitchPage(ELoginPage.lpMailAccLogin);
                   TNavTabView.FocusLoginTab(TLoginModule.LOGIN_ACCOUNT_TYPE.KMailLogin);
               else
                    -- 获取快速登录列表
                    local zList = TLoginModule.GetQuickAccList();
                    if nil ~= zList and zList.count > 0 then
                        TLoginCtrl.SwitchPage(ELoginPage.lpQKLogin);
                    elseif login_qrcode_config.qrcode_prior_show() then -- 配置优先使用二维码登录
                        TLoginCtrl.SwitchPage(ELoginPage.lpQRLogin);
                    else
                        TLoginCtrl.SwitchPage(ELoginPage.lpAccLogin);
                    end;
                    TNavTabView.FocusLoginTab(TLoginModule.LOGIN_ACCOUNT_TYPE.kQQLogin);
               end
            end

            TNavTabView.FocusLoginTab(login_type);
            TNavTabView.ShowView(true);
        else
            TGPLog.LogI("LoginC", "Scan end, not scan UI.");
        end;
    end;

    -- 显示异地登录
    OnShowKickOff = function(nEvtID, sJson)
        ierd_tgp.tpf_ui.Require("wegame_login\\kickoff.lua");
        TKickOffView.ShowView(sJson);
    end;
    
    OnAccountUnregister = function(nEvtID, sJson)
        ierd_tgp.tpf_ui.Require("wegame_login\\account_unreg.lua");
        TAccountUnregister.ShowView(sJson);
    end;
    
    OnAccountUnregisterUpdateExitTime = function(nEvtID, sJson)
        ierd_tgp.tpf_ui.Require("wegame_login\\account_unreg.lua");
        TAccountUnregister.OnUpdateExitTime(sJson);
    end;

    OnShowUserKickOffNotify = function(param_tbl)
        ierd_tgp.tpf_ui.Require("wegame_login\\kickoff.lua");
        TKickOffView.ShowUserKickOffView(param_tbl);
    end;

    OnChangeRegionSuccNotify = function(para_tbl)
        ierd_tgp.tpf_ui.Require("wegame_login\\kickoff.lua");
        -- TKickOffView.ShowChangeRegionSuccView(para_tbl);
    end;

    OnShowBlackListUserNotify = function(para_tbl)
        ierd_tgp.tpf_ui.Require("wegame_login\\kickoff.lua");
        TKickOffView.ShowBlackListUserView(para_tbl);
    end;
    -- 服务器状态
    OnWGSvrState = function(nEvtID, sJson)
        local   zParam = base_utility.json_to_table(sJson);

        if nil ~= zParam then
            TLoginModule.SetSvrState(zParam.login_succ);
            TGPLog.LogI("LoginC", "Login server state:"..tostring(zParam.login_succ));
        else
            TGPLog.LogE("LoginC", "Login server state, J2T fail.");
        end;
    end;

    -- 密码保护
    OnPwdGuardChk = function(uEvtID, sJson)
        TLoginView.ShowPwdGuardChk(sJson);
    end;

    -- 显示二维码登录
    OnShowQRLogin = function(uEvtID, sJson)
        if TLoginCtrl.bQRStop then
            TGPLog.LogI("LoginC", "Show QRLogin, QRLogin already stopped.");
            return;
        end;

        local zInfo = base_utility.json_to_table(sJson);
        

        if nil ~= zInfo and
            (TQRLoginError.QRLOGIN_ERROR_TIMEOUT == zInfo.status or 
            TQRLoginError.QRLOGIN_ERROR_FETCH_FAILED == zInfo.status) and
            TLoginView.nCurPage ~= ELoginPage.lpQRLogin then
            TGPLog.LogI("LoginC", "Show QRLogin, CurPage is not QRLogin.");
            return;
        end

        if TLoginCtrl.SwitchPage(ELoginPage.lpQRLogin) then
            
            if nil == zInfo then
                TGPLog.LogE("LoginC", "QRLogin, get QR information fail.");
                return;
            end;

            -- 0代表是二维码下载ok，1代表等待手机确认状态,2二维码超时,3等待验证
            if TQRLoginError.QRLOGIN_ERROR_OK == zInfo.status then -- 下载OK(sso的二维码图片)
                TLoginView.ShowQRImage();
            elseif TQRLoginError.QRLOGIN_ERROR_CONFIRM == zInfo.status then -- 等待手机确认
                TLoginView.ShowQRConfirm();
            elseif TQRLoginError.QRLOGIN_ERROR_TIMEOUT == zInfo.status then -- 超时
                TLoginView.ShowQRTimeOut();
            elseif TQRLoginError.QRLOGIN_ERROR_VERIFYING == zInfo.status then -- 验证中
                TLoginView.ShowRQChecking();
            elseif TQRLoginError.QRLOGIN_ERROR_FETCH_FAILED == zInfo.status then -- 拉取二维码失败
                TLoginView.ShowQRFailed();
            else
                TGPLog.LogE("LoginC", "QRLogin, Unknown status:"..tostring(zInfo.status));
            end;
        else
            TGPLog.LogE("LoginC", "QRLogin, switch to QR page fail.");
        end;
    end;

    -- 显示二维码登录
    OnShowWeChatQRLogin = function(zParamTbl)
        if TLoginView.IsSamePage(ELoginPage.lpWeChatQRLogin) then
            if nil == zParamTbl then
                TGPLog.LogE("LoginC", "QRLogin, get QR information fail.");
                return;
            end;

            -- 0:代表是二维码拉取ok，1:代表二维码获取失败,2:二维码超时,3:已扫描，等待手机确认，4：用户点击了取消
            if 0 == zParamTbl.error_code then           -- 获取二维码成功
                TLoginView.ShowWeChatQRImage();
            elseif 1 == zParamTbl.error_code then       -- 获取二维码失败
                TLoginView.ShowWeChatQRGetFail();
            elseif 2 == zParamTbl.error_code then       -- 二维码鉴权超时
                TLoginView.ShowWeChatQRTimeOut();
            elseif 3 == zParamTbl.error_code then         -- 已扫描，等待手机确认
                TLoginView.ShowWeChatQRScaned();
            elseif 4 == zParamTbl.error_code then         -- 用户点击了取消
                TLoginCtrl.OnGetWeChatQRcode();  -- fixbug  点了取消后要刷新图片，否则再次扫描点登录会失败
                TLoginView.ShowWeChatQRImage();          -- 允许再次扫描
            else
                TGPLog.LogE("LoginC", "QRLogin, Unknown status:"..tostring(zParamTbl.error_code));
            end;
        else
            TGPLog.LogE("LoginC", "QRLogin, switch to QR page fail.");
        end;
    end;
    -- 微信鉴权成功
    OnWeChatQRAuthSucc = function()
        TLoginCtrl.SwitchPage(ELoginPage.lpLogining);
        local zStatus = {};
        zStatus["state"] = TStrHelper.GetString(EStrDefine.STR_WECHAT_AUTH_SUCC);
        TLoginView.SetStatus(zStatus);
    end;

    -- 尝试重新登录
    OnSvrRelogin = function(zParam)
        TLoginCtrl.OnLoginGoBack();
    end;

    -- 尝试重新发送登录请求
    OnSvrRetry = function(zParam)
        local   zInfo = TLoginModule.GetCurInfo();

        if nil ~= zInfo and TLoginCtrl.DoWGLogin(zInfo) then
            TGPLog.LogI("LoginC", "Login retry.");
        else
            TLoginCtrl.OnLoginGoBack();
            TGPLog.LogE("LoginC", "Get last login information fail.");
        end;
    end;

    -- 是否可离线登录
    OnSvrCanOffline = function(zParam)
        local   zRtn = {};

        if TLoginModule.CanOfflineLogin() then
            zRtn["can_offline"] =  1;
        else
            zRtn["can_offline"] =  0;
        end;

        return zRtn;
    end;

    DoWGLogin = function(zParam)
        local   bSucc = false;

        -- 首先把之前的登录失败信息清理掉
        TLoginModule.SetFailInfo(false, nil);

        -- 离线模式处理
        if TLoginModule.IsOfflineLaunch() then
            return TLoginModule.DoOfflineLogin(zParam);
        end;

        -- 判断登录方式
        if ELoginType.ltQKLogin == zParam["type"] then          -- Quick login
            bSucc = TLoginModule.QuickLogin(zParam["uin"]);
        elseif ELoginType.ltSavedAcc == zParam["type"] then     -- History account login
            bSucc = TLoginModule.LoginByHistory(zParam["uin"], zParam["opt"]);
        elseif ELoginType.ltTEdit == zParam["type"] then        -- TEdit密码登录
            bSucc = TLoginModule.LoginByTedit(zParam["uin"], zParam["opt"]);
        elseif ELoginType.ltMailLogin == zParam["type"] then
            bSucc = TLoginModule.LoginByMail(zParam["sub_type"], zParam["mail_acc"], zParam["pwd"], zParam["opt"]);
        else        -- QR login
            TGPLog.LogE("LoginC", "Unknown login type:"..tostring(zParam["type"]));
        end;

        -- 保存信息
        if bSucc then
            zParam["eCurLoginType"] = TLoginModule.eCurLoginType;
            TLoginModule.SetCurInfo(zParam);
            TGPLog.LogI("LoginC", "Start logining.");
            return true;
        else
            TGPLog.LogI("LoginC", "Login fail.");
            return false;
        end;
    end;

    -- 登录
    OnSvrWGLogin = function(zParam)
        if TLoginCtrl.DoWGLogin(zParam) then
            zParam["succ"] = true;
        else
            zParam["succ"] = false;
        end;

        return zParam;
    end;

    -- 删除指定帐号
    OnSvrDelAcc = function(zParam)
        -- 删除成功，刷新帐号列表
        if TLoginModule.DelAccByUin(tonumber(zParam["uin"])) then
            TLoginView.SetSavedList(TLoginModule.GetSavedList());
        end;
    end;

    -- 删除指定的邮箱账号
    OnSvrDelMailAcc = function (zParam)
       -- 删除成功，刷新账号列表
        if TLoginModule.DelAccByMail(zParam["acc_name"]) then
            TLoginView.SetMailSavedList(TLoginModule.GetMailSavedList());
        end;
    end;

    -- 退出WeGame
    OnSvrExitWG = function(zParam)
        TGPLog.LogI("LoginC", "Exit wegame service.");

        if 1 == zParam["report"] then
            TLoginCtrl.ReportClose();
        end;

        TLoginView.HideView();
        layout_mgr.hide_all_window();
        ierd_tgp.tpf_ui.ExitTGP();
    end;

    OnSvrRestart = function(zParam)
        TLoginModule.RestartWG();
    end;

    OnSvrTASExit = function(zParam)
        -- 有安全登录框，不退出
        if not TLoginModule.HasTEdit() then
            TGPLog.LogI("LoginC", "TASExit, TEdit control created.");
            return;
        end;

        -- 是WeGame登录，并且不是快速登录，提示安全风险
        if TLoginModule.IsWeGameLogin() and 
           not TLoginView.IsLastPage(ELoginPage.lpQKLogin) and
           not TLoginView.IsSamePage(ELoginPage.lpQKLogin) then

            local   zParam = {};

            -- "发现安全风险，无法登录，请重新启动腾讯游戏客户端！"  97
            zParam["err_msg" ] = TStrHelper.GetString(EStrDefine.STR_SECFORBID_LOGIN);
            zParam["err_code"] = 97;
            TLoginCtrl.ShowLoginError(zParam);
        end;
    end;

    -- TAS退出
    OnTASExit = function(nEvtID, sJson)
        TLoginCtrl.OnSvrTASExit(nil);
    end;

    -- TAS扫描到安全环境危险
    OnTASDanger = function(nEvtID, sJson)
        if not TLoginCtrl.bMainShow then
            TLoginView.ShowTASTips();
        end;

        -- 数据上报
        local   zTemp = ierd_tgp.tpf_ui.LuaQosDataEx:new();

        zTemp.oc_type    = 1;
        zTemp.qos_kind   = ierd_tgp.adapt_for_imports.qos.Qos_kind.kTASScanDanger;
        zTemp.str_action = "TASScan";
        zTemp.str_type   = "TASDanger";
        zTemp.str_json   = "{}";

        base_utility.lua_qos_ex(zTemp);
        zTemp:delete();
    end;

    -- 回退上一个页面
    OnLoginGoBack = function(zParam)
        local   nIndex = TLoginView.GetLastPage();

        if nIndex >= ELoginPage.lpMinPage and nIndex < ELoginPage.lpMaxPage then
            TLoginCtrl.SwitchPage(nIndex);
        else
            TLoginCtrl.SwitchPage(ELoginPage.lpAccLogin);
        end;
    end;

    -- 显示登录失败
    ShowLoginError = function(zParam)
        -- 离线模式处理，可以在这里
        -- 如果是登录错误信心，则立即显示
        TLoginCtrl.SwitchPage(ELoginPage.lpLoginErr);
        TLoginView.SetStatus(zParam);
    end;

    -- 登录开始
    OnLoginBegin = function(nEvtID, sJson)
        TLoginCtrl.SwitchPage(ELoginPage.lpLogining);

        local zStatus = {};

        zStatus["state"] = TStrHelper.GetString(EStrDefine.STR_VALID_ACC_STATE);
        TLoginView.SetStatus(zStatus);

        local   zInfo = base_utility.json_to_table(sJson);

        -- 保存正在登录中的信息
        if nil ~= zInfo then
            TLoginModule.SetCurUin(tonumber(zInfo.uin));
        end;
    end;

    -- 登录失败
    OnLoginFail = function(nEvtID, sJson)
        local   zInfo = nil;
        if nil ~= sJson and "" ~= sJson then
            TGPLog.LogI("LoginC", "Login fail:" .. sJson);
            zInfo = base_utility.json_to_table(sJson);
        end;
        
        if nil == zInfo then
            TGPLog.LogE("LoginC", "Login fail, parameter is null.");
            zInfo = {};
        end;

        -- 因为登录失败时，传过来的UIN是err_code，所以这里设置
        zInfo["uin"] = TLoginModule.GetCurUin();

        if zInfo["err_code"] == 7610424 then
            local ext_msg = zInfo["err_msg"] or "";
            zInfo["err_msg"] = LoadStr("LOGIN_MGR_TWOFA_FAILED");

            local split_string = function(str, sep)
                local sep, fields = sep or ":", {}
                local pattern = string.format("([^%s]+)", sep)
                string.gsub(str,pattern, function(c) fields[#fields+1] = c end)
                return fields
            end;

            if nil ~= string.find(ext_msg, "need_2fa") then
                local auth_info = split_string(ext_msg, '|');
                if #auth_info ~= 3 then
                    TGPLog.LogE("LoginC", "Login fail, invalid 2fa param");
                else
                    login_auth_verify_model.code_2fa = auth_info[2] or "";
                    login_auth_verify_model.machine_id = auth_info[3] or "";
                    if "" ~= login_auth_verify_model.code_2fa then
                        comm_center.call_service("i_service_show_login_auth_verify_window", {});
                        return;
                    end
                end
            end
        end

        TLoginCtrl.ShowLoginError(zInfo);
        TLoginModule.SetCurUin(0);
        TLoginView.UnInitWebPict();
    end;

    -- 登录成功
    OnLoginSucc = function(nEvtID, sJson)
        local   zStatus = {};
        zStatus["state"] = TStrHelper.GetString(EStrDefine.STR_STATE_SCAN_GAME);
        TLoginView.SetStatus(zStatus);

        local   zParam = base_utility.json_to_table(sJson);

        if nil ~= zParam then
            TLoginModule.SetLoginUin(zParam["uin"]);
            TLoginModule.SetTGPID(zParam["tgp_id"]);
            TLoginModule.SetLoginAccountType(zParam["account_type"]);
        end;
    end;

    -- Get login uin
    OnSvrGetLoginUin = function(zParam)
        zParam["uin"] = TLoginModule.GetLoginUin();
        return zParam;
    end;

    -- 显示错误信息
    OnSvrShowError = function(zParam)
        TLoginCtrl.SwitchPage(ELoginPage.lpLoginErr);
        TLoginView.SetStatus(zParam);
    end;

    -- 验证码
    OnPictCheck = function(nEvtID, sJson)
        local data = base_utility.json_to_table(sJson);
        if nil ~= data and nil ~= data.new_pic_url and "" ~= data.new_pic_url then
            TGPLog.LogE("LoginC", "OnPictCheck:webpict");
            TLoginCtrl.SwitchPage(ELoginPage.lpAccLogin)
            TLoginView.ShowWebPict(data.new_pic_url);
        else
            if TRUE ==TNewPictCheck.IsWebPictVisible() then
                -- 如果新版本验证码已经显示出来了，就不要显示旧版验证码了
                return;
            end
            if (TLoginCtrl.SwitchPage(ELoginPage.lpPictChk)) then
                TGPLog.LogE("LoginC", "OnPictCheck:oldpict");
                TLoginView.SetStatus(base_utility.json_to_table(sJson));
            else
                TGPLog.LogE("LoginC", "Switch to picture check page fail.");
            end;
        end
    end;

    -- 显示主界面
    OnShowMain = function(nEvtID, sJson)
        if TLoginCtrl.bMainShow then
            TGPLog.LogI("LoginC", "OnShowMain, main already show or is hide login.");
            return;
        end;

        TLoginCtrl.bMainShow = true;
        TLoginModule.NotifyClose();

        if not TLoginModule.IsHideLogin() then
            TLoginView.HideView();
        end;
        TLoginView.SetCouldShowNavTab(false);
        event_center.post_event(login_event.LOGIN_EVT_CHECK_SVRTIPS, "", true);

        -- 取消所有事件监听
        TLoginCtrl.UnListenAllEvts();
    end;

    OnCheckSvrTips = function(nEvtID, sJson)
        if (false == TLoginModule.GetSvrState()) and (false == TLoginModule.GetShowFailTips()) then
            TGPLog.LogI("LoginC", "Connect TGP server fail, show tips.");
            TLoginView.ShowSvrErrTips();
            TLoginModule.SetShowFailTips(true);
        end;
    end;

    OnSvrWeGameSDKLoginFailed = function(zParam)
        TGPLog.LogI("LoginC", "OnSvrWeGameSDKLoginFailed, show tips.");
        TLoginView.ShowSvrErrTips();
        TLoginModule.SetShowFailTips(true);
    end;
    -- 启动TIPS
    OnShowLaunchTips = function(nEvtID, zParam)
        TLoginView.ShowWGTips(true);
    end;
 
    -- 正在升级，不可登录
    OnMsgUpdate = function(zParam)
        if true == TLoginCtrl.bMainShow then
            -- 如果主界面已经显示了，说明登录窗口已经销毁，不再处理更新的消息，避免crash
            return;
        end
        TLoginModule.SetTVerHasRsp(true);
        TLoginModule.SetCanLogin(false);
        TLoginCtrl.SwitchPage(ELoginPage.lpUpdating);
    end;

    -- 升级检测结果
    OnUpdateChk = function(zParam)
        TLoginModule.SetTVerHasRsp(true);

        -- 无需升级 或者 TVersion服务器登录超时，允许登录
        if EUpdateErrCode.erNoUpdate    == zParam["ErrCode"] or
           EUpdateErrCode.erTVerTimeOut == zParam["ErrCode"] then
            TLoginModule.SetCanLogin(true);
        else
            -- 需要升级，或者升级失败，即使之前显示了登录失败，也需要升级，升级优先级最高
            TLoginModule.SetCanLogin(false);
            TLoginCtrl.SwitchPage(ELoginPage.lpUpdating);
        end;
    end;

    -- 刷新二维码
    OnRenewQR = function(zParam)
        TLoginCtrl.bQRStop = false;
        TLoginModule.StartQRLogin();
    end;

    -- 拉取微信二维码
    OnGetWeChatQRcode = function()
        local req_code_tbl = comm_center.call_service("Srv_GetWeChatQRCode",{});
        if req_code_tbl.req_result_code ~= 0 then
            -- 请求失败，给提示
            TLoginView.ShowWeChatQRGetFail();
        end
    end;

    -- 停止QR登录
    OnSvrStopQR = function(zParam)
        TLoginCtrl.bQRStop = true;
        TLoginCtrl.OnLoginGoBack();
    end;

    -- 停止WeChatQR登录
    OnSvrStopWeChatQR = function()
        TLoginCtrl.bWeChatQRStop = true;
        TLoginCtrl.SwitchPage(ELoginPage.lpAccLogin);   -- 切账号和密码页面
    end;


    -- 显示右侧区域
    OnSvrShowContent = function(zParam)
        if 0 == zParam["show"] then
            TLoginView.HideContent();
        else
            TLoginView.ShowContent();
        end;
    end;

    -- QR配置变更
    OnQRCfgChange = function(nEvtID, sJson)
        if nil == sJson then
            TGPLog.LogE("LoginC", "QR config change, json is null.");
            return;
        end;

        local   zParam = base_utility.json_to_table(sJson);

        if nil ~= zParam then
            local   bEnable = false;

            if TLoginModule.IsNetBar() then
                bEnable = zParam["netbar_channel_id"];
            else
                bEnable = zParam["regular_channel_id"];
            end;

            TLoginView.ShowQRButton(bEnable, login_qrcode_config.show_qrcode_animation());
        end;
    end;

    -- 取消登录
    OnCancelLogin = function(zParam)
        -- 取消登录
        TLoginModule.CancelLogin(zParam["service_id"], zParam["uin"]);

        -- 回退到上一个界面
        TLoginCtrl.OnLoginGoBack();
    end;

    -- 刷新验证码
    OnRenewPict = function(zParam)
        TLoginModule.UpdatePict(zParam["service_id"]);
    end;

    -- 验证码验证
    OnValidPict = function(zParam)
        TLoginModule.ValidPict(zParam["service_id"], zParam["code"]);
    end;

    -- 是否为隐藏登录
    OnSvrIsHideLogin = function(zParam)
        if TLoginModule.IsHideLogin() then
            zParam["hide"] = 1;
        else
            zParam["hide"] = 0;
        end;

        return zParam;
    end;

    -- 更新登录广告
    OnLoginADUpdate = function(data)
        if login_model.running_mode == login_model.OFFLINE_MODE then
            TGPLog.LogE("LoginC", "offline mode , not show login ad");
            return;
        end;
        TLoginModule.SetLoginAD(data);
        TLoginView.UpdateLoginAD(data);
    end;

    GetLoginAdData = function()
        local temp_data = TLoginModule.login_ad_data;
        -- 为了规避跨域加载问题，将本地地址改为wegame域名地址
        if nil ~= temp_data.ad_tpl_url then
            local a, b, file = string.find(temp_data.ad_tpl_url,
                "tpf_ui\\res\\dl\\local_login_ad\\(.+)");
            if nil ~= file then
                temp_data.ad_tpl_url =
                    "http://wegame.gtimg.com/g.55555-r.c4663/client_res/local_login_ad/" .. file;
            end
        end
        return temp_data;
    end;

    -- 切换用户登录
    OnSwitchUserLogin = function(data)
        if data == nil or data.force_switch == nil or data.force_switch == 1 then
            event_center.send_event(main_web_event.TGP_CLOSE, "{}");

            local pGMLib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");

            if nil ~= pGMLib then
                pGMLib:do_switch_user();
            else
                TGPLog.LogE("LoginC", "Switch user, game library is null.");
            end;
        else
            -- TODO: show switch tips when any game is running
        end;
    end;

    -- 获取用户UIN服务
    OnSvrGetUin = function(zData)
        local   zTemp = 
                {
                    main_uin = login_model.main_uin, 
                    current_uin = login_model.current_uin
                };

        return zTemp;
    end;

    -- 退出上报
    ReportClose = function()
        local tParam = ierd_tgp.tpf_ui.LuaQosData:new();

        tParam.oc_type = ierd_tgp.tpf_ui.kInstant;
        tParam.qos_report_id = ierd_tgp.adapt_for_imports.qos.Qos_kind.kCloseLoginRpt;
        tParam.int_val[0] = TLoginModule.GetOnlineTime();
        tParam.int_count = 1;

        base_utility.lua_qos(tParam);
        tParam:delete();
    end;

    -- 用户信息变化
    OnSelfInfo = function(uEvtID, sJson)
        local   zInfo = base_utility.json_to_table(sJson);

        if nil == zInfo then
            TGPLog.LogI("LoginC", "Self information change, J=>T fail.");
            return;
        end;

        -- 下载
        local   zParam = {};

        zParam["uin"     ] = tostring(zInfo["uin"]);
        zParam["icon_url"] = zInfo["user_icon"];
        zParam["tgp_id"] = zInfo["tgp_id"];
        comm_center.call_service("Svr_UpdateUserIcon", zParam);
    end;
    -- 查询是否是黑机器（只针对网吧版本）
    QueryIsBlackMachine = function()
        if TLoginModule.IsNetBar() then 
            local param = {};
            param["is_netbar"] = 1;
            comm_center.call_service("Srv_QueryBlackMachine", param);
        end
    end;

    OnQueryBlackMachineRlt = function(zParamTbl)
        if zParamTbl ~= nil and zParamTbl.risk_level ~= nil and zParamTbl.risk_level > 0 then
            local strTips = LoadStr(ID_BLACK_MACHINE_ALERT_TEXT);
            if zParamTbl.alert_string ~= nil and zParamTbl.alert_string ~= "" then
                strTips = zParamTbl.alert_string;
            end
            TLoginModule.SetBlcakMachineState(true);
            TLoginModule.SetBlackMachineAlertText(strTips);
            if TLoginView.IsSamePage(ELoginPage.lpQRLogin) then
                TLoginView.ShowTasBMTips(true, strTips);
            end
        else
            TLoginModule.SetBlcakMachineState(false);
        end
    end;


    OnSvrIsI18NVer = function (zTemp)
        local   pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");
        local   zTemp = {};

        if (nil ~= pTPFUI) then
            if pTPFUI:Is_International_ver() then
                zTemp["is_overseas_ver"] = 1;
            else
                zTemp["is_overseas_ver"] = 0;
            end;
        else
            zTemp["is_overseas_ver"] = 0;
        end;

        return zTemp;
    end;

    OnGetCurLanguage = function(zTemp)
        local   pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");
        local   zTemp = {};

        if (nil ~= pTPFUI) then
            local ret = pTPFUI:get_current_language();
            zTemp["language"] = ret;
        else
            zTemp["language"] = 0;
        end;

        return zTemp; 
    end;

    OnSetLanguage = function(zTemp)
        local   pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");
        if (nil ~= pTPFUI and zTemp ~= nil) then
            local language = zTemp["language"];
            local ret = pTPFUI:set_language(language);
        end
    end;

    OnMailBeiginLogin = function ()
        TLoginCtrl.SwitchPage(ELoginPage.lpLogining);

        local zStatus = {};

        zStatus["state"] = TStrHelper.GetString(EStrDefine.STR_VALID_ACC_STATE);
        TLoginView.SetStatus(zStatus);
    end;

    OnMainWndRestore = function()
        if TKickOffView ~= nil and TKickOffView.bNeedShowChangeRegionWnd then
            TKickOffView.ShowChangeRegionSuccView();
        end
    end;

    OnMainWndShow = function()
        TLoginCtrl.OnMainWndRestore();
    end;

    OnGetDPIAwareMode = function (data)
        if nil == data then
            data = {};
        end;
        local pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");
        if nil ~= pTPFUI then
            data.mode = pTPFUI:GetDPIAwareMode();
        end
        return data;
    end;

    OnSetDPIAwareMode = function(data)
        if nil == data or nil == data.mode then
            return;
        end
        local pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");
        if nil ~= pTPFUI then
            pTPFUI:SetDPIAwareMode(data.mode);
        end
    end;

    OnShowFistProtocalView = function(data)
        TGPLog.LogE("LoginC", "OnShowFistProtocalView, data.");
        TLoginView.HidePickCheckView();
        TLoginView.HideLoginView();
        local version = data["protocal_version"];
       login_first_protocal_view.show(TLoginView.root_id,version);
    end;

    OnShowUpdateProtocalView = function(data)
        TGPLog.LogE("LoginC", "OnShowUpdateProtocalView, data.");
        TLoginView.HideLoginView();
        TLoginView.HidePickCheckView();
        local version = data["protocal_version"];
        local protocal_content = data["protocal_content"];
        login_update_protocal_view.show(TLoginView.root_id, version, protocal_content);
    end;

    OnCloseProtocalView = function(data)
       TLoginView.ShowLoginView();
    end;


    bFstShow  = true;   -- 是否是首次显示
    bQRStop   = false;  -- QR登录是否已经停止
    bMainShow = false;  -- 主窗口是否已经显示

    bIsLauncher = false;     -- 是否launcher启动
    zLaunchCmdInfo = {};      -- 启动信息命令行参数
};

TLoginCtrl.InitCtrl();